package com.heima.health.controller;

import com.heima.health.entity.QueryPageBean;
import com.heima.health.entity.Result;
import com.heima.health.pojo.CheckItem;
import com.heima.health.service.CheckItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("checkitem")
@Api(tags = "检查项管理开发")
public class CheckItemController {

    @Reference
    private CheckItemService checkItemService;

    @GetMapping("findAll")
    @ApiOperation(value = "查询所有",notes = "查询所有检查项列表信息")
    public Result findAll(){
        return new Result(checkItemService.list());
    }

    @PostMapping("findPage")
    @ApiOperation(value = "分页查询",notes = "分页查询所有检查项列表信息")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        return new Result(checkItemService.findPage(queryPageBean));
    }

    @PostMapping("saveOrUpdate")
    @ApiOperation(value = "添加或更新检查项",notes = "携带id时更新，不携带id时添加检查项")
    public Result saveOrUpdate(@RequestBody CheckItem checkItem){
        if (checkItem.getId()==null){
            //新增时设置is_delete为0
            checkItem.setIs_delete(0);
        }
        //新增或删除，有id时更新，无id时添加
        return new Result(checkItemService.saveOrUpdate(checkItem));
    }

    @DeleteMapping("deleteById/{id}")
    @ApiOperation(value = "逻辑删除",notes = "根据id删除检查项")
    public Result deleteById(@PathVariable("id") Integer id){
        CheckItem checkItem=new CheckItem();
        checkItem.setId(id);
        checkItem.setIs_delete(1);
        return new Result(checkItemService.updateById(checkItem));
    }
}
